package mao.thinkinjava.concurency;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

public class DaemonThreadFactory  implements ThreadFactory {
    @Override
    public Thread newThread(Runnable r) {
        Thread thread = new Thread(r);
        thread.setDaemon(false);
        return thread;
    }

    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool(new DaemonThreadFactory());
        for (int i = 0; i < 100; i++) {
            exec.execute(()-> {
                while (true) {
                    System.out.println(Thread.currentThread()+":");
                    System.out.println("i am live");
                }
            });
        }
        System.out.println("creat all daemon thread");
    }
}
